package model;

public class CounterClockwiseProtocol extends PhilosopherProtocol{

	private final DiningPermissionToken rightToken;
	private final DiningPermissionToken leftToken;

	public CounterClockwiseProtocol(final DiningPermissionToken leftToken, final DiningPermissionToken rightToken) {
		this.leftToken = leftToken;
		this.rightToken = rightToken;
	}

	@Override
	public void onThinkingState() {
		leftToken.get();
		this.getPhilosopher().setState(LeftTokenObtained.getInstance());
	}

	@Override
	public void onLeftTokenObtainedState() {
		rightToken.get();
		this.getPhilosopher().setState(Eating.getInstance());
	}

	@Override
	public void onEatingState() {
		this.getPhilosopher().setState(StopEating.getInstance());
	}

	@Override
	public void onStopEating() {
		rightToken.put();
		leftToken.put();
		this.getPhilosopher().setState(Thinking.getInstance());
	}
}
